**
** Replication Do-File for F1000 Publication
** Katsunori Seki
** Created: 11-26-2021
** Updated: 12-16-2021
**

use "nondem_elec.dta", clear

**-------------------------------------**
** Baseline Specification and Figure 1 **
**-------------------------------------**

logit gwf_failure /*
   */ pe_short pe_long5 pe_exante pe_noexante /* 
   */ le_short le_long5 le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)

** Coefficient plots
coefplot, xline(0, lcol(gray)) legend(off) omitted baselevels /*
*/ mfcolor(gray) ciopts(lcolor(gray))  /*
*/ headings(pe_short = "{bf:Presidential Elections}" /*
*/          le_short = "{bf:Legislative Elections}" /*
*/          gwf_military = "{bf:Controls}", labcolor(red) labgap(-120)) /*
*/ drop(_cons EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia y* gwf_duration*) /*
*/ yscale(alt noline) coeflabels(, labgap(-115) notick) /*
*/ graphregion(margin(l=65) color(white))    
graph export "baseline.png", replace


**-------------------------------------------------------**
** Main Model and Marginal Effect Plots (Figures 2 to 5) **
**-------------------------------------------------------**

logit gwf_failure /*
   */ pe_short pe_short_pbyc_c pe_long5 pe_long5_pbyc_c pbyc_c pe_exante pe_noexante /*
   */ le_short le_short_pbyc_c le_long5 le_long5_pbyc_c lbyc_c le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)
*sum year if e(sample)
*tab cname if e(sample)

** Coefficient plots
coefplot, xline(0, lcol(gray)) legend(off) omitted baselevels /*
*/ mfcolor(gray) ciopts(lcolor(gray))  /*
*/ headings(pe_short = "{bf:Presidential Elections}" /*
*/          le_short = "{bf:Legislative Elections}" /*
*/          gwf_military = "{bf:Controls}", labcolor(red) labgap(-130)) /*
*/ drop(_cons EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia y* gwf_duration*) /*
*/ yscale(alt noline) coeflabels(, labgap(-125) notick) /*
*/ graphregion(margin(l=68) color(white))    
graph export "interaction.png", replace

** Graph the marginal effects
logit gwf_failure /*
   */ c.pe_short##c.pbyc_c c.pe_long5##c.pbyc_c pe_exante pe_noexante /*
   */ c.le_short##c.lbyc_c c.le_long5##c.lbyc_c le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)

margins, dydx(pe_short) /*
    */ at(pbyc_c = 0)   /*
	*/ at(pbyc_c = .5)  /*
	*/ at(pbyc_c = 1)   /*
	*/ at(pbyc_c = 1.5) /*
	*/ at(pbyc_c = 2)   /*
	*/ at(pbyc_c = 2.5) /*
	*/ at(pbyc_c = 3)   /* 
	*/ at(pbyc_c = 3.5) /*
	*/ at(pbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-.1 .3)) ylabel(-.1 (.1) .3, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-.1 0 .1 .2 .3, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "pe_short.png", replace	
   
margins, dydx(pe_long5) /*
    */ at(pbyc_c = 0)   /*
	*/ at(pbyc_c = .5)  /*
	*/ at(pbyc_c = 1)   /*
	*/ at(pbyc_c = 1.5) /*
	*/ at(pbyc_c = 2)   /*
	*/ at(pbyc_c = 2.5) /*
	*/ at(pbyc_c = 3)   /* 
	*/ at(pbyc_c = 3.5) /*
	*/ at(pbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-.3 .1)) ylabel(-.3 (.1) .1, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-.3 -.2 -.1 0 .1, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "pe_long.png", replace	
   
margins, dydx(le_short) /*
    */ at(lbyc_c = 0)   /*
	*/ at(lbyc_c = .5)  /*
	*/ at(lbyc_c = 1)   /*
	*/ at(lbyc_c = 1.5) /*
	*/ at(lbyc_c = 2)   /*
	*/ at(lbyc_c = 2.5) /*
	*/ at(lbyc_c = 3)   /* 
	*/ at(lbyc_c = 3.5) /*
	*/ at(lbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-.3 .4)) ylabel(-.3 (.1) .4, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-.3 -.2 -.1 0 .1 .2 .3 .4, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "le_short.png", replace	
   
margins, dydx(le_long5) /*
    */ at(lbyc_c = 0)   /*
	*/ at(lbyc_c = .5)  /*
	*/ at(lbyc_c = 1)   /*
	*/ at(lbyc_c = 1.5) /*
	*/ at(lbyc_c = 2)   /*
	*/ at(lbyc_c = 2.5) /*
	*/ at(lbyc_c = 3)   /* 
	*/ at(lbyc_c = 3.5) /*
	*/ at(lbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-1 .6)) ylabel(-1 (.5) .6, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-1 -.5 0 .5, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))      
graph export "le_long.png", replace	

**----------**
** Appendix **
**----------**

**-------------------------------**
** Regression Results (Table A1) **
**-------------------------------**

cd "/Users/kseki/Dropbox/KS/JournalSubmission/202111F1000/"
use "2021nov_ea_data.dta", clear

eststo clear
** Baseline Specification
eststo: logit gwf_failure /*
   */ pe_short pe_long5 pe_exante pe_noexante /* 
   */ le_short le_long5 le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)
** Main Model 
eststo: logit gwf_failure /*
   */ pe_short pe_short_pbyc_c pe_long5 pe_long5_pbyc_c pbyc_c pe_exante pe_noexante /*
   */ le_short le_short_pbyc_c le_long5 le_long5_pbyc_c lbyc_c le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)
** Alternative measure of opposition boycott
eststo: logit gwf_failure /*
   */ pe_short pe_short_pbyc_o pe_long5 pe_long5_pbyc_o pbyc_o pe_exante pe_noexante /*
   */ le_short le_short_pbyc_o le_long5 le_long5_pbyc_o lbyc_o le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)
** Use vote/seat share
eststo: logit gwf_failure /*
   */ pvs_short pvs_short_pbyc_c pvs_long5 pvs_long5_pbyc_c pbyc_c pe_exante pe_noexante /*
   */ lvs_short lvs_short_pbyc_c lvs_long5 lvs_long5_pbyc_c lbyc_c le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)

esttab using "logit_results.tex", se star(* 0.10 ** 0.05 *** 0.01) replace
clear

**-------------------**
** Robustness Checks **
**-------------------**

cd "/Users/kseki/Dropbox/KS/JournalSubmission/202111F1000/"
use "2021nov_ea_data.dta", clear

** (1) Alternative measure of opposition boycott
logit gwf_failure /*
   */ c.pe_short##c.pbyc_o c.pe_long5##c.pbyc_o pe_exante pe_noexante /*
   */ c.le_short##c.lbyc_o c.le_long5##c.lbyc_o le_exante le_noexante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)

margins, dydx(pe_short) /*
    */ at(pbyc_o = 0)   /*
	*/ at(pbyc_o = 1)   /*
	*/ at(pbyc_o = 2)   /*
	*/ at(pbyc_o = 3)   /* 
	*/ at(pbyc_o = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray))  /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-.1 .3)) ylabel(-.1 (.1) .3, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4") /*
	*/ yline(-.1 0 .1 .2 .3, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "pe_short_d.png", replace	
   
margins, dydx(pe_long5) /*
    */ at(pbyc_o = 0)   /*
	*/ at(pbyc_o = 1)   /*
	*/ at(pbyc_o = 2)   /*
	*/ at(pbyc_o = 3)   /* 
	*/ at(pbyc_o = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray))  /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-.3 .1)) ylabel(-.3 (.1) .1, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4") /*
	*/ yline(-.3 -.2 -.1 0 .1, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "pe_long_d.png", replace	
   
margins, dydx(le_short) /*
    */ at(lbyc_o = 0)   /*
	*/ at(lbyc_o = 1)   /*
	*/ at(lbyc_o = 2)   /*
	*/ at(lbyc_o = 3)   /* 
	*/ at(lbyc_o = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray))  /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-.3 .5)) ylabel(-.3 (.1) .5, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4") /*
	*/ yline(-.3 -.2 -.1 0 .1 .2 .3 .4 .5, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "le_short_d.png", replace	
   
margins, dydx(le_long5) /*
    */ at(lbyc_o = 0)   /*
	*/ at(lbyc_o = 1)   /*
	*/ at(lbyc_o = 2)   /*
	*/ at(lbyc_o = 3)   /* 
	*/ at(lbyc_o = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray))  /*
	*/ title("") xtitle("Opposition Boycott") ytitle("") /*
	*/ yscale(range(-1 .6)) ylabel(-1 (.5) .6, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4") /*
	*/ yline(-1 -.5 0 .5, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))      
graph export "le_long_d.png", replace	
   
** (2) Use vote/seat share 
logit gwf_failure /*
   */ c.pvs_short##c.pbyc_c /*
   */ c.pvs_long5##c.pbyc_c /*
   */ c.lvs_short##c.lbyc_c /*
   */ c.lvs_long5##c.lbyc_c /*
   */ pe_noexante pe_exante le_noexante le_exante /*
   */ gwf_military gwf_party gwf_monarchy /*
   */ lag_nl_gdppc_maddison lag_growth_maddison lag_hm_oil_dependence /*
   */ EEurope_PostSoviet NAfrica_MiddleEast SubsaharanAfrica LatinAmerica Asia /*
   */ y1940s y1950s y1960s y1970s y1980s y1990s /*
   */ gwf_duration gwf_duration2 gwf_duration3, cluster(gwf_caseid)
   
margins, dydx(pvs_short) /*
    */ at(pbyc_c = 0)   /*
	*/ at(pbyc_c = .5)  /*
	*/ at(pbyc_c = 1)   /*
	*/ at(pbyc_c = 1.5) /*
	*/ at(pbyc_c = 2)   /*
	*/ at(pbyc_c = 2.5) /*
	*/ at(pbyc_c = 3)   /* 
	*/ at(pbyc_c = 3.5) /*
	*/ at(pbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("") ytitle("") /*
	*/ yscale(range(-.1 .3)) ylabel(-.1 (.1) .3, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-.1 0 .1 .2 .3, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "pvs_short.png", replace	
	
margins, dydx(pvs_long5) /*
    */ at(pbyc_c = 0)   /*
	*/ at(pbyc_c = .5)  /*
	*/ at(pbyc_c = 1)   /*
	*/ at(pbyc_c = 1.5) /*
	*/ at(pbyc_c = 2)   /*
	*/ at(pbyc_c = 2.5) /*
	*/ at(pbyc_c = 3)   /* 
	*/ at(pbyc_c = 3.5) /*
	*/ at(pbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("") ytitle("") /*
	*/ yscale(range(-.3 .1)) ylabel(-.3 (.1) .1, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-.3 -.2 -.1 0 .1, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "pvs_long.png", replace
   
margins, dydx(lvs_short) /*
    */ at(lbyc_c = 0)   /*
	*/ at(lbyc_c = .5)  /*
	*/ at(lbyc_c = 1)   /*
	*/ at(lbyc_c = 1.5) /*
	*/ at(lbyc_c = 2)   /*
	*/ at(lbyc_c = 2.5) /*
	*/ at(lbyc_c = 3)   /* 
	*/ at(lbyc_c = 3.5) /*
	*/ at(lbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("") ytitle("") /*
	*/ yscale(range(-.1 .3)) ylabel(-.1 (.1) .3, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-.1 0 .1 .2 .3, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))   
graph export "lvs_short.png", replace
   
margins, dydx(lvs_long5) /*
    */ at(lbyc_c = 0)   /*
	*/ at(lbyc_c = .5)  /*
	*/ at(lbyc_c = 1)   /*
	*/ at(lbyc_c = 1.5) /*
	*/ at(lbyc_c = 2)   /*
	*/ at(lbyc_c = 2.5) /*
	*/ at(lbyc_c = 3)   /* 
	*/ at(lbyc_c = 3.5) /*
	*/ at(lbyc_c = 4) 
marginsplot, recast(line) plot1opts(lcolor(gray) mcolor(gray)) ciopt(color(gray)) recastci(rarea) /*
	*/ title("") xtitle("") ytitle("") /*
	*/ yscale(range(-.4 .2)) ylabel(-.4 (.1) .2, nogrid angle(0)) /*
	*/ xscale(range(1 4)) xlabel(1 "0" 2 "0.5" 3 "1" 4 "1.5" 5 "2" 6 "2.5" 7 "3" 8 "3.5" 9 "4") /*
	*/ yline(-.4 -.3 -.2 -.1 0 .1 .2, lcolor(gray) lpattern(dot)) /*
	*/ graphregion(color(white))        
graph export "lvs_long.png", replace
   

